package main

import (
	gee4 "gee/day4-group/gee"
	"log"
	"net/http"
	"time"
)

func main() {
	gee := gee4.New()
	gee.Use(gee4.Logger())
	gee.GET("/", func(c *gee4.Context) {
		c.HTML(http.StatusOK, "<h1>hello Gee </h1>")
	})

	v2 := gee.Group("/v2")
	v2.Use(onlyForV2())
	{
		v2.GET("/hello/:name", func(c *gee4.Context) {
			c.String(http.StatusOK, "hello %s, you're at %s \n", c.Param("name"), c.Path)
		})
	}

	gee.Run("127.0.0.1:9999")
}

func onlyForV2() gee4.HandlerFunc {
	return func(c *gee4.Context) {
		t := time.Now()
		//c.Fail(500, "Internal Server Error")
		log.Printf("[%d] %s in %v for group v2 ", c.StatusCode, c.Req.RequestURI, time.Since(t))
	}
}
